﻿namespace wToggl
{
    using System;

    using Windows.UI.Xaml.Controls;

    using GoogleAnalytics;
    using GoogleAnalytics.Core;

    using wToggle.Platform;
    using wToggle.Platform.Interfaces;

    class PhoneAnalyticsProvider : IAnalytics
    {
        public void ReportException(Exception ex, bool isFatal = false)
        {
            EasyTracker.GetTracker().SendException(ex.ToString(), isFatal);
        }

        public void ReportPageVisit(Page page)
        {
            EasyTracker.GetTracker().SendView(page.GetType().Name);
        }

        public void Dispatch()
        {
            GAServiceManager.Current.Dispatch();
        }

        public void ReportEvent(EventCategory category, EventAction action, string label)
        {
            if (string.IsNullOrEmpty(label))
            {
                throw new ArgumentNullException("label");
            }

            EasyTracker.GetTracker()
                .SendEvent(
                    category.GetAttributeValue<AnalyticsEnumValueAttribute, string>(arg => arg.Value),
                    action.GetAttributeValue<AnalyticsEnumValueAttribute, string>(arg => arg.Value),
                    label,
                    0);
        }
    }
}
